package com.itheima05;

import com.sun.org.apache.regexp.internal.RE;

import java.util.function.Predicate;

public class PredicateDemo02 {
    public static void main(String[] args) {
        boolean b1 = checkString("hello", s -> s.length() > 8);
        System.out.println(b1);

        boolean b2 = checkString("hello world", s -> s.length() > 8);
        System.out.println(b2);

        boolean b3 = checkString("hello", s -> s.length() > 8, s -> s.length() < 10);
        System.out.println(b3);

        boolean b4 = checkString("hello world", s -> s.length() > 8, s -> s.length() < 15);
        System.out.println(b4);
    }

    // 同一个字符串，给出两个不同的判断条件，两个结果做逻辑运算
    private static boolean checkString(String s, Predicate<String> p1, Predicate<String> p2) {
//        boolean b1 = p1.test(s);
//        boolean b2 = p2.test(s);
//        return b1 && b2;

//        return p1.and(p2).test(s);

        return p1.or(p2).test(s);
    }

    // 判断字符串是否满足要求
    private static boolean checkString(String s, Predicate<String> p) {
        return p.test(s);
    }
}
